package com.wgh.product.service.impl;

import com.wgh.product.entity.shop.ProductProductTag;
import com.wgh.product.mapper.ProductProductTagMapper;
import com.wgh.product.service.ProductProductTagService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 商品标签关联Service实现类
 * 
 * @author AI Shop
 */
@Service
public class ProductProductTagServiceImpl extends ServiceImpl<ProductProductTagMapper, ProductProductTag> implements ProductProductTagService {

    @Override
    public List<Long> getTagIdsByProductId(Long productId) {
        return baseMapper.selectTagIdsByProductId(productId);
    }

    @Override
    public List<Long> getProductIdsByTagId(Long tagId) {
        return baseMapper.selectProductIdsByTagId(tagId);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean addBatch(List<ProductProductTag> productProductTags) {
        return baseMapper.insertBatch(productProductTags) > 0;
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteByProductId(Long productId) {
        return baseMapper.deleteByProductId(productId) > 0;
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteByTagId(Long tagId) {
        return baseMapper.deleteByTagId(tagId) > 0;
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteByProductIdAndTagIds(Long productId, List<Long> tagIds) {
        return baseMapper.deleteByProductIdAndTagIds(productId, tagIds) > 0;
    }
}